{template 'common/header'}
<div id="js-wxapp-edit" ng-controller="WxappEditCtrl" ng-cloak>
	<div class="container">
		<div class="caret-wxapp">
			<div class="panel panel-app">
				<div class="wxapp-head panel-heading">
					<!--头部信息-->
					<img src="./resource/images/9.png" alt="公众号头像" class="">
					<span class="wxapp-name">{$wxapp_info['name']}</span>
					<span class="wxapp-version">{$version_info['version']}</span>
					<div class="pull-right">
						<a href="{php echo url('wxapp/version/switch_version', array('uniacid' => $_GPC['uniacid']))}" class="color-default"><i class="wi wi-cut"></i>切换版本</a>
						<a href="{php echo url('wxapp/post', array('uniacid' => $_GPC['uniacid']))}" class="color-default"><i class="wi wi-text"></i>设计新版本</a>
						<a href="{php echo url('wxapp/display/display')}" class="color-default"><i class="wi wi-small-routine"></i>切换小程序</a>
					</div>
					<!--end头部信息-->
				</div>
				<div class="panel-body">
					<div class="left-menu">
						<!--菜单列表-->
						{if $version_info['design_method'] == 2}
						<div class="panel panel-menu">
							<div class="panel-heading">
								首页设置<span class="fa fa-cog pull-right"></span>
							</div>
							<ul class="list-group">
								<li class="list-group-item" ng-class="{active : wxapp == 'slide'}" ng-click="wxapp = 'slide'">
									<a href=""><i class="wi wi-img"></i>幻灯片 </a>
								</li>
								<li class="list-group-item" ng-class="{active : wxapp == 'nav'}" ng-click="wxapp = 'nav'">
									<a href=""><i class="wi wi-template"></i>导航图标</a>
								</li>
								<li class="list-group-item" ng-class="{active : wxapp == 'recommend'}" ng-click="wxapp = 'recommend'">
									<a href=""><i class="wi wi-appmsg"></i>推荐图片</a>
								</li>
							</ul>
						</div>
						{/if}
						<div class="panel panel-menu">
							<div class="panel-heading">
								模块
							</div>
							<ul class="list-group">
								{loop $module_connections $module}
								<a href="{php echo url('home/welcome/ext', array('m' => $module['name'], 'uniacid_source' => 'wxapp', 'uniacid' => !empty($connection[$module['name']]) ? $connection[$module['name']] : $_GPC['uniacid']))}" target="_blank" onclick="if(!confirm('您当前操作的公众号与该模块关联的公众号不一致，确定要切换并前往{$module['link_name']}公众号下的{$module['title']}模块')) return false;">
								<li class="list-group-item">
									<i class="fa fa-adjust"></i>{$module['title']}
								</li>
								</a>
								{/loop}
							</ul>
						</div>
						<!--end菜单列表-->
						<div class="panel panel-menu">
							<div class="panel-heading">
								基础设置
							</div>
							<ul class="list-group">
								<li class="list-group-item" ng-class="{active : wxapp == 'setting'}" ng-click="wxapp = 'setting'">
									<i class="wi wi-appsetting"></i>关联设置
								</li>
								</a>
							</ul>
						</div>
					</div>
					<div class="right-content">
						<div class="wxapp-slide-project">
							<!--预览-->
							<div class="wxapp-phone" ng-show="wxapp != 'setting'">
								<img src="./resource/images/iphone6.png" alt="" class="wxapp-phone-bg" />
								<!--预览内容-->
								<div class="wxapp-home-preview">
									<img src="./resource/images/173.png"/>
								</div>
								<!--end预览内容-->
							</div>
							<!--end预览-->
							{if $version_info['design_method'] == 2}
							<div class="wxapp-slide" ng-show="wxapp != 'setting'">
								<!--列表-->
								<div class="wxapp-slide-list" ng-show="wxapp == 'slide'">
									<div class="slide-heading">
										幻灯片
									</div>
									<ul>
										{loop $slides $slide}
										<li>
											<div class="wxapp-slide-detail media">
												<div class="media-left media-middle slide-sort">
													{$slide['displayorder']}
												</div>
												<div class="media-left media-middle slide-img">
													<img src="{php echo tomedia($slide['thumb'])}"/>
												</div>
												<div class="media-body">
													<div class="slide-title">
														{$slide['title']}
													</div>
													<div class="slide-alter">
														<a href="" ng-click="slideedit({$slide['id']})" class="color-default">编辑</a>
														<a href="{php echo url('wxapp/version/edit', array('id' => $slide['id'], 'operate' => 'delete', 'type' => 'slide', 'multiid' => $multiid, 'version_id' => $_GPC['version_id'], 'uniacid' => $_GPC['uniacid']))}" onclick="return confirm('确认删除幻灯片吗');" class="color-default">删除</a>
													</div>
												</div>
											</div>
										</li>
										{/loop}
										<li class="slide-list-more">
											<a href=""  class="slide-add" ng-click="slideedit('add')">+</a>
										</li>
									</ul>
								</div>
								<div class="wxapp-slide-list" ng-show="wxapp == 'nav'">
									<div class="slide-heading">
										导航图标
									</div>
									<ul>
										{loop $navs $nav}
										<li>
											<div class="wxapp-slide-detail media">
												<div class="media-left media-middle slide-sort">
													{$nav['displayorder']}
												</div>
												<div class="media-left media-middle slide-img">
													<image src="{php echo tomedia($nav['icon'])}"></image>
													<icon class="{if !empty($nav['css'])}{$nav['css']['icon']['icon']}{/if}"></icon>
												</div>
												<div class="media-body">
													<div class="slide-title">
														{$nav['name']}
													</div>
													<div class="slide-alter">
														<a href="" class="color-default" ng-click="navedit({$nav['id']})">编辑</a>
														<a href="{php echo url('wxapp/version/edit', array('type' => 'nav', 'id' => $nav['id'], 'operate' => 'delete', 'multiid' => $multiid, 'version_id' => $_GPC['version_id'], 'uniacid' => $_GPC['uniacid']))}" onclick="return confirm('确认删除导航吗？');" class="color-default slide-del">删除</a>
													</div>
												</div>
											</div>
										</li>
										{/loop}
										<li class="slide-list-more">
											<a href="" class="slide-add" ng-click="navedit('add')">+</a>
										</li>
									</ul>
								</div>
								<div class="wxapp-slide-list" ng-show="wxapp == 'recommend'">
									<div class="slide-heading">
										推荐
									</div>
									<ul>
										{loop $recommends $recommend}
										<li>
											<div class="wxapp-slide-detail media">
												<div class="media-left media-middle slide-sort">
													{$recommend['displayorder']}
												</div>
												<div class="media-left media-middle slide-img">
													<img src="{php echo tomedia($recommend['thumb'])}"/>
												</div>
												<div class="media-body">
													<div class="slide-title">
														{$recommend['title']}
													</div>
													<div class="slide-alter">
														<a href="" class="color-default" ng-click="recommendedit({$recommend['id']}, '{$recommend['pcate']}')">编辑</a>
														<a href="{php echo url('wxapp/version/edit', array('operate' => 'delete', 'type' => 'article', 'id' => $recommend['id'], 'multiid' => $multiid, 'uniacid' => $_GPC['uniacid'], 'version_id' => $_GPC['version_id']))}" onclick="return confirm('确认删除推荐吗？')" class="color-default slide-del">删除</a>
													</div>
												</div>
											</div>
										</li>
										{/loop}
										<li class="slide-list-more">
											<a href="javascript:void(0)" class="slide-add" ng-click="recommendedit('add')">+</a>
										</li>
									</ul>
								</div>
								<div class="wxapp-slide-edit" ng-show="wxapp == 'slideedit'">
									<div class="edit-heading">
										<a href="" class="go-back">
											<i class="fa fa fa-chevron-circle-left"></i>
										</a>
										<span class="color-gray">幻灯片列表 / </span>
										<span class="color-dark">新建幻灯片</span>
									</div>
									<form action="{php echo url('wxapp/version/edit', array('multiid' => $multiid, 'uniacid' => $_GPC['uniacid'], 'version_id' => $_GPC['version_id']))}" method="post" class="form we7-form" enctype="multipart/form-data">
										<div class="form we7-form" ng-if="slideid == 'add'">
											<div class="form-group" >
												<label for="" class="control-label col-sm-2">标题</label>
												<div class="form-controls col-sm-10">
													<input type="text" required name="slide[title]" class="form-control input-slide-title"  placeholder="">
												</div>
											</div>
											<div class="form-group">
												<label for="" class="control-label col-sm-2">排序</label>
												<div class="form-controls col-sm-10">
													<input type="text" name="slide[displayorder]" class="form-control input-slide-sort" id="" placeholder="">
												</div>
											</div>
											<div class="form-group">
												<label for="" class="control-label col-sm-2">图片</label>
												<div class="form-controls col-sm-10">
													{php echo tpl_form_field_image('slide[thumb]', '')}
												</div>
											</div>
											<div class="form-group">
												<label for="" class="control-label col-sm-2">链接</label>
												<div class="form-controls col-sm-10">
													<input type="text" name="slide[url]" class="form-control input-slide-link" required placeholder="">
												</div>
											</div>
											<input type="submit" name="submit" value="添加" class="btn btn-primary" />
											<input type="hidden" name="token" value="{$_W['token']}" />
										</div>
										{loop $slides $slide}
										<div class="form we7-form" ng-if="slideid == {$slide['id']}">
											<div class="form-group" >
												<label for="" class="control-label col-sm-2">标题</label>
												<div class="form-controls col-sm-10">
													<input type="text" name="slide[title]" class="form-control input-slide-title" required value="{$slide['title']}" placeholder="">
												</div>
											</div>
											<div class="form-group">
												<label for="" class="control-label col-sm-2">排序</label>
												<div class="form-controls col-sm-10">
													<input type="text" name="slide[displayorder]" class="form-control input-slide-sort" id="" value="{$slide['displayorder']}" placeholder="">
												</div>
											</div>
											<div class="form-group">
												<label for="" class="control-label col-sm-2">图片</label>
												<div class="form-controls col-sm-10">
													{php echo tpl_form_field_image('slide[thumb]', $slide['thumb'])}
												</div>
											</div>
											<div class="form-group">
												<label for="" class="control-label col-sm-2">链接</label>
												<div class="form-controls col-sm-10">
													<input type="text" name="slide[url]" class="form-control input-slide-link" required value="{$slide['url']}" id="" placeholder="">
												</div>
											</div>
											<input type="submit" name="submit" value="提交" class="btn btn-primary" />
											<input type="hidden" name="token" value="{$_W['token']}">
											<input type="hidden" name="id" value="{$slide['id']}">
										</div>
										{/loop}
									</form>
								</div>
								<div class="wxapp-slide-edit" ng-show="wxapp == 'navedit'">
									<div class="edit-heading">
										<a href="" class="go-back">
											<i class="fa fa fa-chevron-circle-left"></i>
										</a>
										<span class="color-gray">导航列表 / </span>
										<span class="color-dark">新建导航图标</span>
									</div>
									<form action="{php echo url('wxapp/version/edit', array('multiid' => $multiid, 'uniacid' => $_GPC['uniacid'], 'version_id' => $_GPC['version_id']))}" method="post" class="form we7-form" enctype="multipart/form-data">
										<div class="form we7-form" ng-if="navid == 'add'">
											<div class="form-group" >
												<label for="" class="control-label col-sm-2">标题</label>
												<div class="form-controls col-sm-10">
													<input type="text" name="nav[name]" required class="form-control input-slide-title"  placeholder="">
												</div>
											</div>
											<div class="form-group">
												<label for="" class="control-label col-sm-2">排序</label>
												<div class="form-controls col-sm-10">
													<input type="text" name="nav[displayorder]" class="form-control input-slide-sort" placeholder="">
												</div>
											</div>
											<div class="form-group">
												<label for="" class="control-label col-sm-2">图片</label>
												<div class="form-controls col-sm-10">
													{php echo tpl_form_field_image('nav[icon]', '')}
												</div>
											</div>
											<div class="form-group">
												<label for="" class="control-label col-sm-2">链接</label>
												<div class="form-controls col-sm-10">
													<input type="text" name="nav[url]" required class="form-control input-slide-link" id="" placeholder="">
												</div>
											</div>
											<input type="submit" name="submit"  value="添加" class="btn btn-primary" />
											<input type="hidden" name="token" value="{$_W['token']}" />
										</div>
										{loop $navs $nav}
										<div class="form we7-form" ng-if="navid == {php echo $nav['id']}">
											<div class="form-group" >
												<label for="" class="control-label col-sm-2">标题</label>
												<div class="form-controls col-sm-10">
													<input type="text" name="nav[name]" required class="form-control input-slide-title" value="{$nav['name']}" placeholder="">
												</div>
											</div>
											<div class="form-group">
												<label for="" class="control-label col-sm-2">排序</label>
												<div class="form-controls col-sm-10">
													<input type="text" name="nav[displayorder]" class="form-control input-slide-sort" id="" value="{$nav['displayorder']}" placeholder="">
												</div>
											</div>
											<div class="form-group">
												<label for="" class="control-label col-sm-2">图片</label>
												<div class="form-controls col-sm-10">
													{php echo tpl_form_field_image('nav[icon]', $nav['icon'])}
												</div>
											</div>
											<div class="form-group">
												<label for="" class="control-label col-sm-2">链接</label>
												<div class="form-controls col-sm-10">
													<input type="text" name="nav[url]" required class="form-control input-slide-link" value="{$nav['url']}" id="" placeholder="">
												</div>
											</div>
											<input type="submit" name="submit" id="" value="提交" class="btn btn-primary" />
											<input type="hidden" name="token" value="{$_W['token']}">
											<input type="hidden" name="id" value="{$nav['id']}">
										</div>
										{/loop}
									</form>
								</div>
								<div class="wxapp-slide-edit" ng-show="wxapp == 'recommendedit'">
									<div class="edit-heading">
										<a href="" class="go-back">
											<i class="fa fa fa-chevron-circle-left"></i>
										</a>
										<span class="color-gray">导航列表 / </span>
										<span class="color-dark">新建导航图标</span>
									</div>
									<form action="{php echo url('wxapp/version/edit', array('multiid' => $multiid, 'uniacid' => $_GPC['uniacid'], 'version_id' => $_GPC['version_id']))}" method="post" class="form we7-form" enctype="multipart/form-data">
										<div class="form we7-form" ng-if="recommendid == 'add'">
											<div class="form-group" >
												<label for="" class="control-label col-sm-2">标题</label>
												<div class="form-controls col-sm-10">
													<input type="text" required name="recommend[title]" class="form-control input-slide-title"  placeholder="">
												</div>
											</div>
											<div class="form-group">
												<label for="" class="control-label col-sm-2">排序</label>
												<div class="form-controls col-sm-10">
													<input type="text" name="recommend[displayorder]" class="form-control input-slide-sort" id="" placeholder="">
												</div>
											</div>
											<div class="form-group form-inline">
												<label for="" class="control-label col-sm-2">分类</label>
												<div class="form-controls col-sm-10">
													<select class="form-control we7-select" name="recommend[pcate]">
														<option>选择分类</option>
														<option ng-repeat="category in categorys" value="{{ category.id }}">{{ category.name }}</option>
													</select>
													<a class="btn btn-default" data-toggle="modal" data-target="#myModal" ng-click="get_categorys()">设置分类</a>
												</div>
											</div>

											<div class="form-group">
												<label for="" class="control-label col-sm-2">图片</label>
												<div class="form-controls col-sm-10">
													{php echo tpl_form_field_image('recommend[thumb]')}
												</div>
											</div>
											<div class="form-group">
												<label for="" class="control-label col-sm-2">链接</label>
												<div class="form-controls col-sm-10">
													<input type="text" name="recommend[source]" required class="form-control input-slide-link" id="" placeholder="">
												</div>
											</div>
											<input type="submit" name="submit"  value="添加" class="btn btn-primary" />
											<input type="hidden" name="token" value="{$_W['token']}" />
										</div>
										{loop $recommends $recommend}
										<div class="form we7-form" ng-if="recommendid == {$recommend['id']}">
											<div class="form-group" >
												<label for="" class="control-label col-sm-2">标题</label>
												<div class="form-controls col-sm-10">
													<input type="text" name="recommend[title]"  required class="form-control input-slide-title" value="{$recommend['title']}" placeholder="">
												</div>
											</div>
											<div class="form-group">
												<label for="" class="control-label col-sm-2">排序</label>
												<div class="form-controls col-sm-10">
													<input type="text" name="recommend[displayorder]" class="form-control input-slide-sort" id="" value="{$recommend['displayorder']}" placeholder="">
												</div>
											</div>
											<div class="form-group form-inline">
												<label for="" class="control-label col-sm-2">分类</label>
												<div class="form-controls col-sm-10">
													<select class="form-control" name="recommend[pcate]">
														<option>选择分类</option>
														<option ng-repeat="category in categorys" value="{{ category.id }}" ng-selected="category.id == {$recommend['pcate']}">{{ category.name }}</option>
													</select>
													<a class="btn btn-default" data-toggle="modal" data-target="#myModal" ng-click="get_categorys()">设置分类</a>
												</div>
											</div>
											<div class="form-group">
												<label for="" class="control-label col-sm-2">图片</label>
												<div class="form-controls col-sm-10">
													{php echo tpl_form_field_image('recommend[thumb]', $recommend['thumb'])}
												</div>
											</div>
											<div class="form-group">
												<label for="" class="control-label col-sm-2">链接</label>
												<div class="form-controls col-sm-10">
													<input type="text" name="recommend[source]" required class="form-control input-slide-link" value="{$recommend['source']}" id="" placeholder="">
												</div>
											</div>
											<input type="submit" name="submit" id="" value="提交" class="btn btn-primary" />
											<input type="hidden" name="token" value="{$_W['token']}">
											<input type="hidden" name="id" value="{$recommend['id']}">
										</div>
										{/loop}
									</form>
									<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
										<div class="modal-dialog modal-dialog-default  modal-lg">
											<div class="modal-content">
												<div class="modal-header">
													<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
													<h4 class="modal-title" id="myModalLabel">分类设置</h4>
												</div>
												<div class="modal-body">
													<table class="table we7-table we7-form">
														<tr>
															<th>类名</th>
															<th>排序</th>
															<th>链接</th>
															<th>操作</th>
														</tr>
														<tbody>
														<tr ng-repeat="category in categorys">
															<td><input ng-model="category.name" class="form-control" size="15"></td>
															<td><input ng-model="category['displayorder']" class="form-control"></td>
															<td><input ng-model="category['linkurl']" class="form-control"></td>
															<td><a href="" ng-click="del_category($index)">删除</a></td>
														</tr>
														<tr>
															<td colspan="4"><a href="javascript:;" class="buttom-add color-default" ng-click="edit_category()" style="text-decoration: none;">添加分类</a></td>
														</tr>
														</tbody>
													</table>
													<!--<button type="button" class="btn btn-primary" ng-click="edit_category()">添加分类</button>-->
													<button type="button" class="btn btn-primary" ng-click="save_category()" style="margin-left: 0px;">保存</button>
												</div>
											</div>
										</div>
									</div>

								</div>
								<!--end列表-->
							</div>
							{/if}
							<div class="we7-page-title" ng-show="wxapp != 'setting'">关联设置</div>
							<div class="we7-padding" ng-show="wxapp != 'setting'">
								<table class="table we7-table table-hover vertical-middle">
									<col width="180px" />
									<col width="140px"/>
									<col width="140px" />
									<tr>
										<th class="text-left">关联设置</th>
										<th class="text-left">公众号</th>
										<th class="text-left">操作</th>
									</tr>
									{loop $module_connections $module $connection}
									<tr >
										<td class="text-left">
											<img src="{$connection['logo']}" style="width:50px;height:50px;">
											{$connection['title']}
										</td>
										<td class="text-left">
											<img src="{$connection['connection']['thumb']}" style="width:50px;height:50px;" class="js-connection-img-{$module}">
											<span class="js-connection-name-{$module}">{$connection['connection']['name']}</span>
										</td>
										<td class="text-left">
											<div class="link-group">
												<a href="javascript:;" class="color-default js-unfold" data-toggle="table-collapse" ng-click="showAccount('{$connection['link_name']}')">修改</a>
											</div>
										</td>
									</tr>
									{/loop}
								</table>
								<div class="modal fade" id="show_account" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
									<div class="modal-dialog we7-modal-dialog" style="width:800px">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
												<h4 class="modal-title">选择公众号(点击选择)</h4>
											</div>
											<div class="modal-body">
												<div class="panel-body we7-padding">
													<div class="row">
														<div ng-if="!account_list.length">
															暂无可选公众号
														</div>
														<div class="col-sm-2 text-center we7-margin-bottom" style="overflow: hidden" ng-repeat="account in account_list" ng-click="selectAccount(current_module, account.uniacid)">
															<a href="javascript:;">
																<img src="{{account.thumb}}" alt="" style="width:50px;height:50px;">
																<p class="text-over">{{account.name}}</p>
															</a>
														</div>
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	angular.module('wxApp').value('config', {
		uniacid : "{php echo $_GPC['uniacid']}",
		multiid : "{php echo $multiid}",
		wxapp : "{php echo $_GPC['wxapp']}" == '' ? 'slide' : "{php echo $_GPC['wxapp']}",
		success_url : "{php echo url('wxapp/version/edit', array('multiid' => $_GPC['multiid'], 'uniacid' => $_GPC['uniacid'], 'version_id' => $_GPC['version_id']))}",
		showAccount_url : "{php echo url('wxapp/version/account_list')}",
		selectAccount_url : "{php echo url('wxapp/version/save_connection', array('version_id' => $versionid))}",
		get_categorys_url : "{php echo url('wxapp/version/get_categorys')}",
		del_category_url : "{php echo url('wxapp/version/del_category')}",
		save_category_url : "{php echo url('wxapp/version/save_category')}",
		links: {
			accountList: "{php echo url('wxapp/version/account_list')}",
			saveConnection: "{php echo url('wxapp/version/save_connection', array('version_id' => $versionid))}",
			getCategorys: "{php echo url('wxapp/version/get_categorys')}",
			delCategory: "{php echo url('wxapp/version/del_category')}",
			saveCategory: "{php echo url('wxapp/version/save_category')}",
		}
	});
	angular.bootstrap($('#js-wxapp-edit'), ['wxApp']);
	change_category = function (element) {
		$.post("{php echo url('wxapp/version/edit', array('operate' => 'change_category'))}", {'categoryid' : element.val()}, function(data) {
			var data = $.parseJSON(data);
			var html = '<option  value="">二级分类</option>';
			var categorys = data.message.message;
			for (var i = 0; i < categorys.length; i++) {
				html += '<option value='+categorys[i]['id']+'>'+categorys[i]['name']+'</option>';
			}
			element.next().html(html);
		});
	};
</script>
</body>
</html>